<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.css"/>" rel="stylesheet">
        <link href="<@spring.url "/resources/plugins/datatables/responsive.dataTables.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title"></h3>
            </div>
            <div class="panel-body">
                <div class="pad-btm form-inline">
                    <div class="row">
                        <div class="col-sm-6 table-toolbar-left">
                            <button id="demo-btn-addrow" class="btn btn-purple" onclick="window.location.href='<@spring.url "/manage/contractInfo/boundList" />'"> 已绑定</button>
                            <button id="demo-btn-addrow" class="btn btn-purple" onclick="window.location.href='<@spring.url "/manage/contractInfo/noBoundList" />'"> 争议未绑定</button>
                            <button id="demo-btn-addrow" class="btn btn-purple" onclick="window.location.href='<@spring.url "/manage/contractInfo/neverBoundList" />'"> 新增量</button>
                        </div>
                        <div class="col-sm-6 table-toolbar-right">
                        </div>
                    </div>
                </div>
                <table id="dt-basic" class="table table-striped table-bordered"
                       cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th><input type="checkbox" /></th>
                        <th>公司名称</th>
                        <th>电压等级(kV)</th>
                        <th class="min-tablet">预估年电量(万kWh)</th>
                        <th class="min-desktop">客户地区</th>
                        <th class="min-desktop">绑定微信</th>
                        <th class="min-desktop">销售</th>
                        <th class="min-desktop">签约模式</th>
                        <th class="min-desktop">操作</th>
                    </tr>
                    </thead>
                    <tbody>
            <#if pageData.content?? && (pageData.content?size>0)>
                <#list pageData.content as data>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><a href="<@spring.url "/manage/companyInfo/edit/${data.companyInfoId}"/>">${(data.companyInfo.name)!}</a></td>
                        <td>${(data.detailInfo.voltageStep)!}</td>
                        <td>${(data.detailInfo.elecConsumption)!}</td>
                        <td>${(data.cityParent.name)!} ${(data.city.name)!}</td>
                        <td>${(data.companyInfo.wxNum)!}</td>
                        <td>${(data.user.name)!}</td>
                        <td>
                            <#if data.planType == 1>1:9分成
                            <#elseif data.planType == 2>全返
                            <#else>
                                <#if (data.contractSetting??)>
                                    <#if data.contractSetting.cooperationType == 1>
                                        ${(100-(data.contractSetting.longAgreementRate)!0)/10}:${((data.contractSetting.longAgreementRate)!0)/10}分成
                                    <#elseif data.contractSetting.cooperationType == 2>
                                        保底 ${(data.contractSetting.bottomPrice)!}
                                    <#elseif data.contractSetting.cooperationType == 4>
                                        ${(data.contractSetting.description)!}
                                    </#if>
                                </#if>
                            </#if>
                        </td>
                        <td>
                            <p>
                                <a href="javascript:void(0)" onclick="showData(${data.id})">资料情况</a>
                                <a href="javascript:void(0)" onclick="sureGeneral(${data.id})">生成合同</a>
                            </p>
                            <p>
                                <#if data.pdfUrl??>
                                    <a href="${FILE_PATH}${data.pdfUrl}" target="_blank">查看合同</a>
                                </#if>
                                <a href="javascript:void(0)" onclick="showFile(${data.id})">其他资料</a>
                            </p>
                            <#if !data.boundStatus??>
                                <a href="javascript:void(0)" onclick="boundContract(${data.id})">绑定</a>
                                <a href="javascript:void(0)" onclick="noBound(${data.id})">争议未绑定</a>
                                <a href="javascript:void(0)" onclick="neverBound(${data.id})">新增量</a>
                            </#if>
                        </td>
                    </tr>
                </#list>
            </#if>
                    </tbody>
                </table>
            </div>
        </div>

    </#if>
    <#if part="modal">
        <!--审核资料-->
        <div class="modal fade" id="userData" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">资料</h4>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="userFile" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">其他资料</h4>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    </#if>

    <#if part="foot_script">
        <script src="<@spring.url "/resources/plugins/datatables/jquery.dataTables.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.responsive.min.js"/>"></script>
        <script src="<@spring.url "/resources/js/tables-datatables.js"/>"></script>
        <script type="text/javascript">
            //$(document).ready( function() {
            $('#dt-basic').dataTable( {
                "fnDrawCallback":function (settings) {
                    $("#dt-basic thead tr th:first").removeClass("sorting_asc");
                    $("#dt-basic tbody tr td:first").removeClass("sorting_asc");
                },
                "aoColumnDefs":[{"bSortable":false, "aTargets":[0]}]
            });
            //});
            function showData(contractInfoId) {

                $.get('<@spring.url "/manage/contractInfo/showContractData" />',
                        {contractInfoId:contractInfoId},
                        function (data) {
                            $("#userData").find(".modal-body").html(data);
                            $("#userData").modal("show");
                        });
            }

            function sureGeneral(id) {
                $.post('<@spring.url "/manage/contractInfo/generatePdf" />',
                        {contractId:id},
                        function (data) {
                            if(data.code==1){
                                alert("生成成功！");
                                window.location.reload();
                            } else {
                                alert(data.message);
                            }
                        });
            }

            function showFile(id) {
                $.get('<@spring.url "/manage/contractInfo/userFile" />',
                        {contractId:id},
                        function (data) {
                            $("#userFile").find(".modal-body").html(data);
                            $("#userFile").modal("show");
                        });
            }

            function deleteFile(fileId) {
                if (confirm("确定要删除当前文件吗？")) {
                    $.post('<@spring.url "/manage/contractInfo/deleteFile" />',
                            {fileId:fileId},
                            function (data) {
                                alert(data.message);
                                window.location.reload();
                            });
                }
            }

            function boundContract(contractInfoId) {
                if (confirm("确定要绑定当前用户吗？")) {
                    $.post('<@spring.url "/manage/contractInfo/boundContract" />',
                        {contractInfoId:contractInfoId},
                        function (data) {
                            alert(data.message);
                            window.location.reload();
                        });
                }
            }

            function noBound(contractInfoId) {
                if (confirm("确定要争议未绑定当前用户吗？")) {
                    $.post('<@spring.url "/manage/contractInfo/noBound" />',
                        {contractInfoId:contractInfoId},
                        function (data) {
                            alert(data.message);
                            window.location.reload();
                        });
                }
            }

            function neverBound(contractInfoId) {
                if (confirm("确定当前用户为新增量用户吗？")) {
                    $.post('<@spring.url "/manage/contractInfo/neverBound" />',
                        {contractInfoId:contractInfoId},
                        function (data) {
                            alert(data.message);
                            window.location.reload();
                        });
                }
            }

            function uploadContractFile(contractInfoId) {
                var file = $("#filePath")[0].files[0];
                var formData = new FormData();
                var name = $("#name").val();
                formData.append("file", file);
                formData.append("name", name);
                formData.append("contractInfoId", contractInfoId);
                $.ajax({
                    type: 'post',
                    url: "<@spring.url "/manage/contractInfo/fileUpload"/>",
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function(data) {
                        alert(data.message);
                        window.location.reload();
                    }
                });
            }

        </script>

    </#if>
</@t.html>